<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <input type="text" v-model='userInfo.firstName'> +
    <input type="text" v-model='userInfo.lastName'> = 
    <input type="text" v-model='userInfo.fullName'> 
  </div>
</body>
<script src="lib/vue.js"></script>
<script>
 
  new Vue({
    el: '#app',
    data: {
      userInfo: {
        firstName: '',
        lastName: '',
        fullName: ''
      }
    },
    watch: {
      // 实际监听的对象下的单个的属性
      // 'userInfo.firstName':function (newVal, oldVal) {
      //   console.log('newVal', newVal)
      //   this.userInfo.fullName = newVal + this.userInfo.lastName
      // },
      // 'userInfo.lastName': function (newVal, oldVal) {
      //   this.userInfo.fullName = this.userInfo.firstName + newVal
      // }
      // 如果需要监听的最外面的对象呢
      userInfo: {
        handler (newVal, oldVal) {
          // this.userInfo.fullName = this.userInfo.firstName + this.userInfo.lastName
          this.userInfo.fullName = newVal.firstName + newVal.lastName
        },
        deep: true
      } 
    }
  })
  
</script>
</html>